package com.demo.result;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

public class R {
    private Integer code;
    private String message;
    private Map<String,Object>data=new HashMap<>();

    private R() {
    }
    public static R success(){
        R r = new R();
        r.setCode(10000);
        r.setMessage("成功");
        return  r;
    }
    public static R error(){
        R r = new R();
        r.setCode(10001);
        r.setMessage("失败");
        return  r;
    }
    public R data(String key,Object value){
        data.put(key,value);
        return this;
    }
    public Object getData(String key){
        return data.get(key);
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "R{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
